home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11564 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.7 KB  |  142 lines

  1. Path: ix.netcom.com!netnews
  2. From: lewkbj@ix.netcom.com(leonel wizel )
  3. Newsgroups: comp.lang.c++
  4. Subject: I need help with homework (Please)
  5. Date: 15 Mar 1996 02:53:00 GMT
  6. Organization: Netcom
  7. Message-ID: <4iam2c$1i7@cloner3.netcom.com>
  8. NNTP-Posting-Host: ix-nyc18-14.ix.netcom.com
  9. X-NETCOM-Date: Thu Mar 14  6:53:00 PM PST 1996
  10.  
  11.     
  12. I have written the following program that contains double subscripted arrays that provides
  13. me with the following:
  14.  
  15.     salesperson Number 1 to 4
  16.     the product number from 1 to 5
  17.  
  18. at the end provides me, with the summarization that includes total products by salesperson
  19. number horizontally, and prints total by product number vertically, but I am missing a way
  20. to input also the total by dollar value in the same way.
  21.  
  22. I need help please:
  23.  
  24. the program is as follows:
  25.  
  26.  
  27. //program prints salespersons products by number and adds them
  28. //by salesperson number and product number
  29.  
  30. #include <iostream.h>
  31. #include <iomanip.h>
  32. #include <math.h>
  33.  
  34. const int S_person = 4;         //number of salespersons
  35. const int prod_sold = 5;        //number of products
  36.  
  37. void Print_Table (float[][S_person], int, int);
  38. void Total_Sales_Person (float[][S_person], int, int);
  39.  
  40. main()
  41. {
  42.     float table[prod_sold][S_person];
  43.  
  44.     for (int x = 0; x < S_person; x++)
  45.     {
  46.     
  47.     cout << endl;
  48.     cout << "Enter the product sold by Sales Person# ["<<(x+1)<<"] one at a time: "<< endl;
  49.     cout << endl;
  50.  
  51.     for (int y = 0; y < prod_sold; y++)
  52.     {
  53.     cout << "Enter product ["<<(y+1)<<"] sold by Sales Person# ["<<(x+1)<<"]: ";
  54.     cin >> table[y][x];
  55.     }
  56.   }
  57.     Print_Table(table, prod_sold, S_person);
  58.     return 0;
  59. }
  60.  
  61. //function Print_Table prints the cable of contents
  62.  
  63. void Print_Table (float sales[][S_person], int prod_sold, int S_person)
  64. {
  65.     float total_prod_sold;
  66.  
  67.     cout << endl;
  68.  
  69.     cout << setw(26) << "sales#[1]" << setw(12) <<"sales#[2]" << setw(12)
  70.          <<"sales#[3]" <<setw(12) << "sales#[4]" << setw(9) <<"Total"
  71.          <<endl;
  72.     cout << endl;
  73.  
  74.     for (int y = 0; y < prod_sold; y++)
  75.     {
  76.         cout << endl;
  77.         cout << setw(8) <<"product["<<(y+1)<<"]";
  78.         total_prod_sold = 0;
  79.  
  80.     for (int x = 0; x < S_person; x++)
  81.     {
  82.     total_prod_sold += sales[y][x];
  83.  
  84.     cout << setw(12) << sales[y][x];
  85.     }
  86.     cout << setw(12) << total_prod_sold;
  87.   }
  88.  
  89.     Total_Sales_Person(sales, prod_sodl, S_person);
  90.     return;
  91. }
  92.  
  93. //function Total_Sales_Person ( adds the total)
  94.  
  95. void Total_Sales_Person (float set_of_sale[][S_person], int prod_sold, int S_person)
  96. {
  97.     float total_sale;
  98.  
  99.     cout << endl;
  100.     
  101.     cout << setw(8) <<"Total Sale" << endl;
  102.  
  103.     for (int x = 0; x < S_person; x++)
  104.     {
  105.         total_sale = 0;
  106.             
  107.             for (int y = 0; y < prod_sold; y++)
  108.             total_sale += set_of_sale[y][x];
  109.  
  110.         cout << endl;
  111.         cout << setw(15) << total_sale << endl;
  112.     }
  113.     return;
  114.  
  115.     I do not know how to improve this program to input/output the total
  116. price in dollars by the products;
  117.  
  118. I need to do the following:
  119.  
  120.     use a double-subscripted array to solve the following problem.  A
  121. company has four sales-people (1-4) who sell five different products (1
  122. to 5).  Once a day, each sales person passes in a slip for each
  123. different type of product sold>  Each slip contains:
  124.  
  125.     1.  The salesperson number
  126.     2.  The product number
  127.     3.  The total dollar value of that product sold that day
  128.  
  129. the program should print a tabular that includes: these cross totals to
  130. the right of the totaled rows and to the bottom of the totaled columns.
  131.  
  132. I was able to solve the prolem of printing the rows of salesitems to
  133. the right and total by salesperson to the bottom but I have to print
  134. the total of the product by dollar sign which I do not have now.
  135.  
  136.     Please I need some help
  137.  
  138.  
  139. I appreciate your cooperation.
  140.  
  141.